// pages/my/my.js
import cache from '../../utils/Cache.js';
import url from '../../utils/url.js';
import http from '../../utils/http.js';
Page({

  /**
   * 页面的初始数据
   */
  data: {
    avator: '../../images/timg.jpg',
    openid: cache.getSorg('openid'),
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
    let that = this;
    if(that.data.openid){
      http.http(url.getuserinfo, 'GET', { openid: that.data.openid }, function (res) {
        that.setData({
          avator: res.userinfo.avatar
        });
      });
    }
    
  },
  bindGetUserInfo:function(evt){
    let that = this;
    let userInfo = evt.detail.userInfo;
    let data = {
      'openid': that.data.openid,
      'nickname': userInfo.nickName,
      'sex': userInfo.gender == 1 ? '男' : '女',
      'avatar': userInfo.avatarUrl
    };
    http.http(url.updateuserinfo, 'POST', data,function(res){
        if(res.status == 0){
            wx.showToast({
              title: '信息更新成功',
            })
          that.setData({
              avator: userInfo.avatarUrl
            });
        }else{
          wx.showToast({
            title: '信息更新失败',
          })
        }
    });
  },
  editUserInfo:function(evt){
    wx.navigateTo({
      url: '../../pages/userinfo/userinfo',
    })
  },
  //个人资料
  userInfo:function(evt){
    wx.navigateTo({
      url: '../../pages/userinfo/userinfo',
    })
  },
  //身份认证
  cardRenZheng:function(evt){
    wx.navigateTo({
      url:'../../pages/cardrenzheng/cardrenzheng'
    })
  },
  //看房通知
  LookNotice:function(){
    wx.navigateTo({
      url:'../../pages/looknotice/looknotice'
    })
  },
  onShow:function(options){
    
  }
})